package com.mxf.agricultural.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mxf.agricultural.constant.CommonConstant;
import com.mxf.agricultural.mapper.AccountMapper;
import com.mxf.agricultural.model.dto.account.AccountQueryRequest;
import com.mxf.agricultural.model.entity.*;
import com.mxf.agricultural.service.AccountService;
import com.mxf.agricultural.utils.SqlUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;


/**
 * @author JD
 * @description 针对表【account】的数据库操作Service实现
 * @createDate 2024-02-11 19:11:26
 */
@Service
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account>
        implements AccountService {

    /**
     * 获取查询包装类
     *
     * @param accountQueryRequest
     * @return
     */
    @Override
    public QueryWrapper<Account> getQueryWrapper(AccountQueryRequest accountQueryRequest) {
        Long userid = accountQueryRequest.getUserid();
        Long balance = accountQueryRequest.getBalance();
        Integer isok = accountQueryRequest.getIsok();
        String sortField = accountQueryRequest.getSortField();
        String sortOrder = accountQueryRequest.getSortOrder();

        QueryWrapper<Account> queryWrapper = new QueryWrapper<>();

        // 拼接查询条件
        queryWrapper.eq(ObjectUtils.isNotEmpty(userid), "userId", userid);
        queryWrapper.eq(ObjectUtils.isNotEmpty(balance), "balance", balance);
        queryWrapper.eq(ObjectUtils.isNotEmpty(isok), "isok", isok);
        queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC),
                sortField);
        return queryWrapper;
    }


}




